package com.siyao.redvip;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.siyao.redvip.bean.UserBean;
import com.siyao.redvip.utils.Constants;
import com.siyao.redvip.utils.Track;
import com.siyao.redvip.volley.NetRequest;

import android.app.Application;
import android.content.Context;
import android.util.Log;
import cn.jpush.android.api.JPushInterface;

/**
 * Appliction
 * Created by Wangxubein on 2015/4/21.
 */
public class RedApplication extends Application {
	
    private static final String TAG = "RedApplication";
    private static RedApplication sInstance;
    private static UserBean user;
    
    public static List<String> mEmoticons = new ArrayList<String>();
    public static Map<String, Integer> mEmoticonsId = new HashMap<String, Integer>();
    public static List<String> mEmoticons_Zem = new ArrayList<String>();
    public static List<String> mEmoticons_Zemoji = new ArrayList<String>();
    
    public static RedApplication getInstance() {
    	if(sInstance == null){
    		sInstance = new RedApplication();
    	}
        return sInstance;
    }

    @Override
    public void onCreate() {
        Log.d(TAG, "RedApplication onCreate");
        sInstance=new RedApplication();
        super.onCreate();
        JPushInterface.setDebugMode(false);    // 设置开启日志,发布时请关闭日志
        JPushInterface.init(this);            // 初始化 JPush
        initImageLoader(getApplicationContext());
        initIcon();//加载表情
    }

	public static UserBean getUser() {
		return user;
	}

	public static void setUser(UserBean user) {
		RedApplication.user = user;
	}
    
	public  void initIcon(){
		for (int i = 1; i < 64; i++) {
            String emoticonsName = "[zem" + i + "]";
            int emoticonsId = getResources().getIdentifier("zem" + i, "drawable", getPackageName());
            mEmoticons.add(emoticonsName);
            mEmoticons_Zem.add(emoticonsName);
            mEmoticonsId.put(emoticonsName, emoticonsId);
        }
	}
	public static void initImageLoader(Context context) {
		 com.nostra13.universalimageloader.utils.L.disableLogging();
	        // 创建配置ImageLoader(所有的选项都是可选的,只使用那些你真的想定制)，这个可以设定在APPLACATION里面，设置为全局的配置参数
	        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
	                .threadPoolSize(3).threadPriority(Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory().memoryCache(new WeakMemoryCache())
	                .discCacheFileNameGenerator(new Md5FileNameGenerator())
	                .tasksProcessingOrder(QueueProcessingType.LIFO).discCache(new UnlimitedDiscCache(new File(Constants.IMAGE_CACHE_DIR)))// 自定义缓存路径
	                .build();
	        ImageLoader.getInstance().init(config);// 全局初始化此配置
	}
}
